<template>
    <div class="shell">
        <ul class="nav">
            <li class="active" id="logo">
                <a href="#">
                    <div class="icon">
                        <div class="imageBox">
                            <img src="../assets/LOGO.PNG" alt="">
                        </div>
                    </div>
                    <div class="text1"><h4>Health Creator</h4></div>
                </a>
            </li>
            <li>
                <router-link to="/home">
                    <div class="icon">
                    </div>
                    <div class="text"><el-icon style="font-size: 35px; padding: 5px;"><HomeFilled /></el-icon> 个人主页</div>
                </router-link>
            </li>
            <li>
                <router-link to="/science">
                    <div class="icon">
                    </div>
                    <div class="text"><img src="../assets/icon_qa7pqywg6i/Science.png" class="img" style="width: 35px; height: 35px;padding: 5px;">健康科普</div>
                </router-link>
            </li>
            <li>
                <router-link to="/mental">
                    <div class="icon">
                    </div>
                    <div class="text"><img src="../assets/icon_qa7pqywg6i/xinli.png" class="img" style="width: 35px; height: 35px;padding: 5px;">心理健康</div>
                </router-link>
            </li>
            <li>
                <router-link to="/telemedicine">
                    <div class="icon">
                    </div>
                    <div class="text"><img src="../assets/icon_qa7pqywg6i/yiliao.png" class="img" style="width: 35px; height: 35px;padding: 5px;">远程医疗</div>
                </router-link>
            </li>
            <li>
                <router-link to="/plans">
                    <div class="icon">
                    </div>
                    <div class="text"><img src="../assets/icon_qa7pqywg6i/jianshen.png" class="img" style="width: 35px; height: 35px;padding: 5px;">健身方案</div>
                </router-link>
            </li>
            <li>
                <router-link to="/community">
                    <div class="icon">
                    </div>
                    <div class="text"><img src="../assets/icon_qa7pqywg6i/Community.png" class="img" style="width: 35px; height: 35px;padding: 5px;">社区互动</div>
                </router-link>
            </li>
            <li>
                <a href="#me">
                    <div class="icon">
                        <div class="imageBox">
                            <img src="../assets/demo.jpg" alt="1">
                        </div>
                    </div>
                    <div class="text2">ME</div>
                    <router-link to="/login">
                    <div class="text3">退出登录</div>
                    </router-link>
                </a>
            </li>
        </ul>
    

</div> 
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'

const $router = useRouter()
const activeIndex = ref(0) // 用于跟踪当前活动的索引
const navItems = ref([]) // 用于存储导航项

onMounted(() => {
    navItems.value = document.querySelectorAll(".nav li")
    navItems.value.forEach((item, index) => {
        item.addEventListener("mouseenter", () => {
            updateActive(index)
        })
        item.addEventListener("mouseleave", () => {
            updateActive(activeIndex.value)
        })
        item.addEventListener("click", () => {
            activeIndex.value = index
            updateActive(activeIndex.value)
        })
    })
})

function updateActive(index) {
    navItems.value.forEach((item, i) => {
        item.classList.remove("active")
        if (i === index) {
            item.classList.add("active")
        }
    })
}
</script>

<style lang="scss" scoped>
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    list-style: none;
    text-decoration: none;
}


.shell {
    position: fixed;
    width: 320px; /* 修改为固定宽度 */
    height: 100%;
    background: #cedc74;
    z-index: 9999;
    transition: width 0.5s; /* 保留过渡效果 */
    padding-left: 10px;
    overflow: hidden;
}


.shell:hover {
    width: 320px; /* 不再需要这个 */
}

.imageBox {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid white; /* 添加白色边框 */
}

.imageBox img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: filter 0.3s ease; /* 添加过渡效果 */
}

.shell ul {
    position: relative;
    height: 100vh;
}

.shell ul li {
    position: relative;
    padding: 5px;
}

.active {
    background: #f8feff;
    border-top-left-radius: 50px;
    border-bottom-left-radius: 50px;
}

.active::before {
    content: "";
    position: absolute;
    top: -30px;
    right: 0;
    width: 30px;
    height: 30px;
    border-bottom-right-radius: 25px;
    box-shadow: 5px 5px 0 5px #f8feff;
    background: transparent;
}

.active::after {
    content: "";
    position: absolute;
    bottom: -30px;
    right: 0;
    width: 30px;
    height: 30px;
    border-top-right-radius: 25px;
    box-shadow: 5px -5px 0 5px #f8feff;
    background: transparent;
}

h4{
    color: #68712e;
}
#logo {
    margin: 40px 0 100px 0;
}

.shell ul li a {
    position: relative;
    display: flex;
    white-space: nowrap;
}

.icon {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 60px;
    padding-left: 10px;
    height: 70px;
    color: #1f1f1f;
    transition: 0.5s;
}

.icon i {
    font-size: 30px;
    z-index: 999;
}

.text1{
    position: relative;
    left: -1px;
    height: 70px;
    display: flex;
    align-items: center;
    font-size: 23px;
    color: #515255;
    padding-left: 15px;
    letter-spacing: 2px;
    transition: 0.5s;
}

.text {
    margin-top: 6px;
    position: relative;
    height: 55px;
    display: flex;
    align-items: center;
    font-size: 20px;
    color: #535662;
    padding-left: 5px;
    letter-spacing: 2px;
    transition: 0.5s;
}

.text2{
    margin-top: 6px;
    position: relative;
    height: 55px;
    display: flex;
    align-items: center;
    font-size: 20px;
    color: #535662;
    padding-left: 8px;
    letter-spacing: 2px;
    transition: 0.5s;
}

.text3{
    color: #5f6826;
    margin-top: 8px;
    position: relative;
    height: 55px;
    display: flex;
    align-items: center;
    font-size: 15px;
    padding-left: 13px;
    letter-spacing: 2px;
    text-decoration: underline;
    transition: 0.5s;
}

.shell ul li:hover a .icon,
.shell ul li:hover a .text {
    color: #5a9dbc;
}

.active a .icon::before {
    content: "";
    position: absolute;
    inset: 5px;
    width: 60px;
    background: #fff;
    border-radius: 50%;
    transition: 0.5s;
    box-sizing: border-box;
}

</style>